package connectionSettings;

import java.util.Vector;

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.midlet.MIDlet;

import util.Preferences;
import connections.Connection;
import connections.ConnectionListener;

public class ConnectionSettings extends Form implements CommandListener, ConnectionListener, ItemStateListener {
	public class BlankCanvas extends GameCanvas {
		Graphics g;

		public BlankCanvas() {
			super(false);
			g = getGraphics();
		}

		public Graphics getMyGraphics() {
			return g;
		}

		public void keyPressed(int keyCode) {
			keyDown(keyCode);
		}

	}

	static public int DELIMITATION_NONE = 0;

	static public int DELIMITATION_END_CHARACTER = 1;

	public static int DELIMITATION_TRASMISSION_LENGTH = 2;

	// int pixelsPerLetter = 8;

	public static int DELIMITATION_TRASMISSION_LENGTH_AND_START_CHAR = 3;

	// public BlankCanvas myCanvas;

	// public Graphics myGraphics;

	public static int getFirstOfMultiple(ChoiceGroup _choices) {

		
		boolean[] checks = new boolean[_choices.size()]; // _recentChoices.size()]; // have to go through this because I used "MULTIPLE"
		
	
		_choices.getSelectedFlags(checks);
		// String choice = null;
		for (int i = 0; i < checks.length; i++) {
			if (checks[i]) {

				// choice = (String) _choices.getString(i); //_recentChoices.elementAt(i);
				return i;
			}
		}
		return -1;
	}

	/**
	 * Split string into multiple strings
	 * 
	 * @param original
	 *            Original string
	 * @param separator
	 *            Separator string in original string
	 * @return Splitted string array
	 */
	public static String[] split(String original, String separator) {
		Vector nodes = new Vector();

		// Parse nodes into vector
		int index = original.indexOf(separator);
		while (index >= 0) {
			nodes.addElement(original.substring(0, index));
			original = original.substring(index + separator.length());
			index = original.indexOf(separator);
		}
		// Get the last node
		nodes.addElement(original);

		// Create splitted string array
		String[] result = new String[nodes.size()];
		if (nodes.size() > 0) {
			for (int loop = 0; loop < nodes.size(); loop++)
				result[loop] = (String) nodes.elementAt(loop);
		}
		return result;
	}

	public String inputString = "";

	boolean clearIt;

	TextField inputField;

	TextField outputField;

	boolean decimalMode;

	ChoiceGroup actionChoices;

	// TextField intervalField;

	// ChoiceGroup pacing;

	TextField address;

	String currentAddress ;

	ConnectionListener cl;

	ConnectionSettingsListener parent;

	Displayable currentDisplay = this;

	Display myDisplay;
	
	Connection myConnection;
	
	TextField endCharField;
	
	TextField startCharField;
	
	TextField transmissionLengthField;
	
	ChoiceGroup delimitation;
	
	boolean showTerminal;

	boolean preferencesShowing;
	

	ChoiceGroup needRequestButton;

	TextField requestCharField;

	int delimitationStyle = 0;

	int startChar = 255;

	int endChar = 13;

	int bytesInTransmission = 26;

	int requestChar = 65;

	boolean needToRequestData;
	
	int interval = 0;

	Preferences prefs;
	
	Form preferenceForm;

	MIDlet myMIDlet;

	Displayable previousDisplay;
	
	int numberOfCommands = 0;

	public ConnectionSettings(String _name) {
		super(_name);
		getPrefs();
		displayConnectionInterface();

	}

	public ConnectionSettings(String _name, ConnectionListener _cl) {
		super(_name);
		cl = _cl;
		getPrefs();
		displayConnectionInterface();
	}
	public ConnectionSettings(String _name, ConnectionSettingsListener _tl) {
		super(_name);
		parent = _tl;
		getPrefs();
		displayConnectionInterface();
	

	}
	
	public void displayMenu(){
	
		if (numberOfCommands == 0){
			
		
			Command prefScreen = new Command("Preferences Hide/Show", Command.OK, 4);
			Command disconnect = new Command("Disconnect", Command.OK, 5);

			Command exit = new Command("Exit", Command.OK, 6);
			
			addCommand(prefScreen);
			addCommand(disconnect);
			addCommand(exit);
			setCommandListener(this);
			numberOfCommands = 2;
		}
		
		if (numberOfCommands < 6 && showTerminal){

			Command clear = new Command("Clear", Command.OK, 1);
			// Command showURL = new Command("Show URL", Command.OK, 3);
			Command decOrText = new Command("Decimal/Text", Command.OK, 2);
			Command askForInput = new Command("Send", Command.OK, 3);
			addCommand(clear);
			// addCommand(showURL);
			addCommand(decOrText);
			addCommand(askForInput);
			numberOfCommands = 5;
		}
	}


	public ConnectionSettings(String _name, Display _d) {
		super(_name);
		myDisplay = _d;
		previousDisplay = _d.getCurrent();
		cl = this;
		getPrefs();
		displayConnectionInterface();
	}

	/**
	 * Asks the connection or the appropriate type of listening based on preferences for startchar, endchar, lenghth of transmission etc.
	 */
	public void addListener(ConnectionListener _cl) {
		if (delimitationStyle == ConnectionSettings.DELIMITATION_END_CHARACTER) {
			myConnection.addListener(_cl, (char) endChar);
		} else if (delimitationStyle == ConnectionSettings.DELIMITATION_TRASMISSION_LENGTH) {
			myConnection.addListener(_cl, bytesInTransmission);
		} else if (delimitationStyle == ConnectionSettings.DELIMITATION_TRASMISSION_LENGTH_AND_START_CHAR) {
			myConnection.addListener(_cl, (char) startChar, bytesInTransmission);
		} else { // take it as fast as it comes in
			myConnection.addListener(_cl);

		}

	}

	public void addMIDlet(MIDlet _midlet) {
		myMIDlet = _midlet;
	}

	public void addToMenu(String _s) {
		Command newCommand = new Command(_s, Command.OK, 5);
		addCommand(newCommand);
	}



	public void commandAction(Command c, Displayable d) {
		String menuChoice = c.getLabel();
		// if (!parent.madeMenuChoice(menuChoice)) {
		if (menuChoice.equals("Exit")) {
			put("Bye");
//System.out.println(previousDisplay + " Exiting Connection Settings" + myMIDlet);
			if (myMIDlet != null) {
				Connection myConnection = getConnection();
				if (myConnection != null) myConnection.disconnect();

				myMIDlet.notifyDestroyed();
			}else if (previousDisplay != null){
				myDisplay.setCurrent(previousDisplay);
			}
		} else if (menuChoice.equals("Disconnect")) {
			Connection myConnection = getConnection();
			if (myConnection != null) myConnection.disconnect();
			displayConnectionInterface();
		} else if (menuChoice.equals("Send")) {
			myConnection.send((byte) requestChar);
			// System.out.println("Sending" + requestChar);
		} else if (menuChoice.toLowerCase().indexOf("preferences") != -1) {
			if (preferencesShowing == false) {
				deleteAll();
				setInterfaceFromVariables();
				displayProtocolOptions();
			} else if (showTerminal){
				setVariablesFromInterface();
				setPrefs();
				deleteAll();
				displayTerminal();
			} else{
				setVariablesFromInterface();
				setPrefs();
				deleteAll();
				displayConnectionInterface();
			}
			preferencesShowing = !preferencesShowing;

		} else if (menuChoice.equals("Clear")) {
			inputString = "";
			inputField.setString(inputString);
			
			// repaint();
			// } else if (menuChoice.equals("Show URL")) {
			// newText("\r" + currentAddress + "\r");
		}
		/*
		 * } else if (menuChoice.equals("Decimal/Text")) { if (decimalMode) { decimalMode = false; myGraphics = myCanvas.getMyGraphics(); Font myFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); myGraphics.setFont(myFont); pixelsPerLetter = 8; } else { decimalMode = true; myGraphics = myCanvas.getMyGraphics(); Font myFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); myGraphics.setFont(myFont); pixelsPerLetter = 20; }
		 * 
		 * repaint(); }
		 */
		// }
		// repaint();
	}
	   public void deleteAll(){
			for(int i = size()-1; i >-1; i--){
				delete(i);
			}
	   }
	public void connectionMade(Connection _c, String _address) {
		//append("here" + (myDisplay == null));
		myConnection = _c; // affirms which connection it is
		setCurrentAddress(_address);
		setPrefs();
		deleteAll();
		//displayTerminal();
		//append("connectionMade in ConnectionSettings" + myDisplay);
		// currentDisplay = myCanvas;
		if ( myDisplay != null) {
			//append("here" + myDisplay);
			displayTerminal();

		}

		// newText("Connected");

	}

	public void displayConnectionInterface() {
		deleteAll();
		actionChoices = new ChoiceGroup("", ChoiceGroup.MULTIPLE);
	
		address = new TextField("Previous ID For Direct Connect:", null, 120, TextField.ANY);
		address.setString(currentAddress);
		append(address);

		if (myDisplay != null) myDisplay.setCurrent(this);
		setInterfaceFromVariables();
		setItemStateListener(this);

		displayMenu();

	}

	public void displayMe(Display _d){
		myDisplay = _d;
		 previousDisplay = _d.getCurrent();
		_d.setCurrent(this);

	}
	public void displayProtocolOptions() {
			// intervalField = new TextField("Sample Interval (ms):", null, 5, TextField.DECIMAL);
		// pacing = new ChoiceGroup("Transmission Pacing", ChoiceGroup.EXCLUSIVE);
		// pacing.append("Wait For Data", null);
		// pacing.append("Poll For Data", null);

		// need a character for just continuous stream
		endCharField = new TextField("End Char:", null, 5, TextField.DECIMAL);
		startCharField = new TextField("Start Char:", null, 5, TextField.DECIMAL);
		transmissionLengthField = new TextField("Length:", null, 5, TextField.DECIMAL);
		requestCharField = new TextField("Request Char:", null, 5, TextField.DECIMAL);
		delimitation = new ChoiceGroup("Delimitation of Incoming", ChoiceGroup.EXCLUSIVE);
		
		delimitation.append("None, Continuous Stream", null);
		delimitation.append("End Character", null);
		delimitation.append("Transmission Length", null);
		delimitation.append("Start Char and Transmission Length", null);
		
		needRequestButton = new ChoiceGroup("Flow Control", ChoiceGroup.MULTIPLE);

		needRequestButton.append("Need To Request", null);

		//append("________________\n");
		append(delimitation);
		append(endCharField);
		append(startCharField);
		append(transmissionLengthField);
		append("________________\n");
		append(needRequestButton);
		append(requestCharField);
		setInterfaceFromVariables();
	}

	public void displayTerminal() {
	//	append("here1");
		showTerminal = true;
		/*
		 * myCanvas = new BlankCanvas(); myGraphics = myCanvas.getMyGraphics(); Font myFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); myGraphics.setFont(myFont); // myCanvas.setCommandListener(this); repaint(); myDisplay.setCurrent(myCanvas);
		 */
		// sizeChanged(100,100);
	
		inputField = new TextField("Incoming:", null, 200, TextField.ANY | TextField.UNEDITABLE);
		inputField.setString("");
		// inputField.setPreferredSize(50, 200);
		outputField = new TextField("Outgoing:", null, 50, TextField.ANY);

		//deleteAll();
		append(currentAddress);
		append(outputField);
		append(inputField);
		displayMenu();
		//append("herew");

	}

	public void feedback(Connection _c, String _feedback) {
		put(_feedback);
	}

	public String[] getAddressParams() {
		if (currentAddress == null)
			currentAddress = address.getString();
		return split(currentAddress, " ");
		// return split(getCurrentAddress(), " ");
	}

	public int getBytesInTransmission() {
		return bytesInTransmission;
	}

	/*
	 * public void startApp() {
	 * 
	 * initCanvas(); initConnection(); if ( myConnection.getAddress() == null) { // don't bother to show the whole connection interface if you already know who you are going to connect with. Display.getDisplay(this).setCurrent(myConnection.getForm()); } else { Display.getDisplay(this).setCurrent(myCanvas); //Display.getDisplay(this).setCurrent(mainForm); } }
	 */

	public Connection getConnection() {
		return myConnection;
	}

	// public String getCurrentAddress() {
	// return address.getString();
	// }

	public String getCurrentAddress() {
		return currentAddress;
	}

	public Displayable getDisplayable() {
		return currentDisplay;
	}

	public int getEndChar() {
		return endChar;
	}

	public int getInterval() {
		return interval;
	}

	public Preferences getPrefs() {

		prefs = new Preferences(this.getClass().getName() + ".prefs");

		String s = prefs.getPref("lastAddress");

		if (s != null) currentAddress = s;

		// s = prefs.getPref("waitForTransmission");
		// if (s != null) waitForTransmission = s.equals("true");
		s = prefs.getPref("needToRequestData");
		if (s != null) needToRequestData = s.equals("true");
		//System.out.println("getting need" + needToRequestData);
		// s = prefs.getPref("interval");
		// if (s != null) interval = Integer.parseInt(s);
		s = prefs.getPref("delimitationStyle");
		if (s != null) delimitationStyle = Integer.parseInt(s);
		System.out.println("Get prefs style" + delimitationStyle);//s = prefs.getPref("transmissionLength");
		//if (s != null) useTransmissionLengthDelim = s.equals("true");
		//s = prefs.getPref("transmissionLengthAndStartChar");
		//if (s != null) useTransmissionLengthAndStartCharDelim = s.equals("true");
		
		s = prefs.getPref("startChar");
		if (s != null) startChar = Integer.parseInt(s);
		s = prefs.getPref("endChar");
		if (s != null) endChar = Integer.parseInt(s);
		s = prefs.getPref("bytesInTransmission");
		if (s != null) bytesInTransmission = Integer.parseInt(s);
		s = prefs.getPref("requestChar");
		if (s != null) requestChar = Integer.parseInt(s);
		return prefs;

	}

	public Displayable getPreviousDisplay() {
		return previousDisplay;
	}

	public int getRequestChar() {
		return requestChar;
	}

	public int getStartChar() {
		return startChar;
	}

	public void incoming(Connection _c, byte[] _input) {
		put(new String(_input));
		if (needToRequestData) {
			send(requestChar);
		}
	}

	public boolean isNeedToRequestData() {
		return needToRequestData;
	}

	// public void setStorageName(String storageName) {
	// this.storageName = storageName;
	// }

	public void itemStateChanged(Item thisItem) {
		try {
			setVariablesFromInterface();
		} catch (NumberFormatException e) {
			System.out.println("Bad Numbers");
		}
		// System.out.println("itemSate" + thisItem.getLabel());
		if (thisItem == actionChoices) {
			int choiceNum = getFirstOfMultiple(actionChoices);
			if (choiceNum != -1) {

				madeChoice(choiceNum, actionChoices.getString(choiceNum));
				if (myConnection != null) {
					if (myConnection.getAddress() != null){
						System.out.println("Set address" + myConnection.getAddress());
						setCurrentAddress(myConnection.getAddress());

						setPrefs();
					}
				}
			}

		} else if (thisItem.getLabel().equals("Outgoing:")) {
			String output = outputField.getString();
			send(output.charAt(output.length() - 1));
		} else if (thisItem.getLabel().equals("Need To Request Data")) {
			needToRequestData = !needToRequestData;
			// boolean[] rFlags = new boolean[1];
			// autoReply.getSelectedFlags(rFlags);
			// System.out.println("before " + rFlags[0]);
			// rFlags[0] = ! rFlags[0];
			needRequestButton.setSelectedIndex(0, needToRequestData);
			// preferences
			// System.out.println("after " + rFlags[0]);

		}

	}

	public void keyDown(int _keycode) {
		send(_keycode);
	}

	public void madeChoice(int _whichChoice, String _choice) {
		// append("Picked " + choices.getSelectedIndex() + " " + _choice);
		if (parent != null) {
			parent.madeChoice(_whichChoice, _choice);
		}

	}

	public void presentActionChoices(String _instructions, Vector _choices) {

		append(_instructions);
		actionChoices.deleteAll();
		for (int i = 0; i < _choices.size(); i++) {
			actionChoices.append((String) _choices.elementAt(i), null);
		}
		setItemStateListener(this);
		append(actionChoices);
		// recentChoices = _choices;
	}

	public void put(String _s) {

		// if (currentDisplay == this) {
		// append(_s);
		// } else {
		// System.out.println("put " + _s);
		if (inputField != null) {
			inputString = inputString + _s;
			if (inputString.length() > 200) {
				inputString = inputString.substring(inputString.length() - 200, inputString.length());
			}
			inputField.setString(inputString);
		} else {
			append(_s);
		}
		// newText(_s);
		// }

	}

	public void replaceDisplay(Display _d) {
		previousDisplay = _d.getCurrent();
		myDisplay = _d;
		myDisplay.setCurrent(this);
	}
	// public String getLastAddress() {
	// return lastAddress;
	// }

	// public void newText(String s) {
	// inputString = inputString + s;
	// repaint();
	// }
	/*
	 * public void repaint() {
	 * 
	 * myGraphics.setColor(230, 230, 230);
	 * 
	 * myGraphics.fillRect(0, 0, myCanvas.getWidth(), myCanvas.getHeight()); int lettersInALine = myCanvas.getWidth() / pixelsPerLetter; int linesInAScreen = myCanvas.getHeight() / 20; myGraphics.setColor(127, 0, 255); Vector allLines = new Vector(); Vector endPoses = new Vector(); int proposedBeginningOfLine = 0;
	 * 
	 * while (proposedBeginningOfLine < inputString.length()) {
	 * 
	 * String thisLine = ""; int proposedEndChar = Math.min(proposedBeginningOfLine + lettersInALine, inputString.length() - 1);
	 * 
	 * while (proposedBeginningOfLine <= proposedEndChar) {
	 * 
	 * char thisChar = inputString.charAt(proposedBeginningOfLine); proposedBeginningOfLine++; if (decimalMode) { int dec = (int) thisChar; thisLine = thisLine + " " + dec; } else { if (thisChar == 13) { break; } thisLine = thisLine + thisChar; } } allLines.addElement(thisLine); endPoses.addElement(new Integer(proposedBeginningOfLine)); } int startLine = allLines.size() - linesInAScreen; int i; for (i = allLines.size() - 1; i > Math.max(-1, startLine); i--) { String thisLine = (String) allLines.elementAt(i); int lineNum = i; if (allLines.size() > linesInAScreen) { lineNum = i - startLine; } myGraphics.drawString(thisLine, 3, lineNum * 20 + 5, 0); } if (i > 0) { // don't let the string get too big Integer cutOff = (Integer) endPoses.elementAt(i - 1); inputString =
	 * inputString.substring(cutOff.intValue(), inputString.length()); }
	 * 
	 * myCanvas.flushGraphics(); }
	 */
	public void send(int _keycode) {

		if (parent != null) {
			parent.keyDown(_keycode);
		} else {

			if (_keycode < 1) {
				myConnection.send((byte) 13);
			} else {
				myConnection.send((byte) _keycode);
			}
		}
	}

	public void setBytesInTransmission(int bytesInTransmission) {
		this.bytesInTransmission = bytesInTransmission;
	}

	//public boolean isUseEndCharacterDelim() {
	//	return useEndCharacterDelim;
	//}

	//public void setUseEndCharacterDelim(boolean endCharacter) {
	//	this.useEndCharacterDelim = endCharacter;
	//}

	public void setCurrentAddress(String currentAddress) {
		this.currentAddress = currentAddress;
	}

	public void setDelimitationStyle(int _delimitationStyle) {
		this.delimitationStyle = _delimitationStyle;
		setInterfaceFromVariables();
	}

	public void setEndChar(int endChar) {
		this.endChar = endChar;
	}

	public void setInterfaceFromVariables() {
		address.setString(currentAddress);
		if (delimitation != null) {
			System.out.println("setInterface" + delimitationStyle);
			boolean[] flags = new boolean[delimitation.size()];
			for (int i = 0; i < delimitation.size(); i++) {
				if (delimitationStyle == i) {
					flags[i] = true;
					break;
				}
			}
			delimitation.setSelectedFlags(flags);

			//boolean[] dflags = { useEndCharacterDelim, useTransmissionLengthDelim, useTransmissionLengthAndStartCharDelim, (useEndCharacterDelim | useTransmissionLengthDelim | useTransmissionLengthAndStartCharDelim) };
			//delimitation.setSelectedFlags(dflags);
			startCharField.setString(String.valueOf(startChar));
			
			boolean[] pflags = { needToRequestData };
			needRequestButton.setSelectedFlags(pflags);
			
			startCharField.setString(String.valueOf(startChar));

			endCharField.setString(String.valueOf(endChar));
			transmissionLengthField.setString(String.valueOf(bytesInTransmission));
			requestCharField.setString(String.valueOf(requestChar));
		}
	}

	public void setInterval(int interval) {
		this.interval = interval;
	}

	public void setNeedToRequestData(boolean requestTransmission) {
		this.needToRequestData = requestTransmission;
	}

	public void setPrefs() {

		prefs.setPref("lastAddress", currentAddress);
		// prefs.setPref("waitForTransmission", String.valueOf(waitForTransmission));
		prefs.setPref("needToRequestData", needToRequestData);
		// prefs.setPref("interval", String.valueOf(interval));
		prefs.setPref("startChar", startChar);
		prefs.setPref("endChar", endChar);
		prefs.setPref("bytesInTransmission", bytesInTransmission);
		prefs.setPref("requestChar", requestChar);
		//prefs.setPref("endCharacter", useEndCharacterDelim);
		//prefs.setPref("transmissionLength", useTransmissionLengthDelim);
		//prefs.setPref("transmissionLengthAndStartChar", useTransmissionLengthAndStartCharDelim);
		prefs.setPref("delimitationStyle", delimitationStyle);
		System.out.println("setPref" + delimitationStyle);

		System.out.println("Saved Prefs");
		prefs.savePrefs();
	}

	public void setPreviousDisplay(Displayable previousDisplay) {
		this.previousDisplay = previousDisplay;
	}

	//public boolean isUseTransmissionLengthDelim() {
	//	return useTransmissionLengthDelim;
	//}

	//public void setUseTransmissionLengthDelim(boolean transmissionLength) {
	//	this.useTransmissionLengthDelim = transmissionLength;
	//}

	//public boolean isUseTransmissionLengthAndStartCharDelim() {
	//	return useTransmissionLengthAndStartCharDelim;
	//}

	//public void setUseTransmissionLengthAndStartCharDelim(boolean transmissionLengthAndStartChar) {
	//	this.useTransmissionLengthAndStartCharDelim = transmissionLengthAndStartChar;
	//}

	public void setRequestChar(int requestChar) {
		this.requestChar = requestChar;
	}

	public void setStartChar(int startChar) {
		this.startChar = startChar;
	}
	public void setVariablesFromInterface() {
		if (delimitation != null){
		currentAddress = address.getString();

			delimitationStyle = ConnectionSettings.getFirstOfMultiple(delimitation);

			startCharField.setLabel("Start Char");
			transmissionLengthField.setLabel("Length (Bytes)");
			if (delimitation != null) {
			endCharField.setLabel("End Char");

			boolean[] pflags = new boolean[needRequestButton.size()];
			needRequestButton.getSelectedFlags(pflags);
			needToRequestData = pflags[0];	
			/*
			 * if (waitForTransmission) { // intervalField.setLabel("Interval Between Recording"); requestCharField.setLabel("Request Char (NA)"); } else { // intervalField.setLabel("Interval Between Requests"); requestCharField.setLabel("Request Char"); }
			 */

			if (delimitationStyle == ConnectionSettings.DELIMITATION_END_CHARACTER) {
				// startCharField.setString("-1");
				// transmissionLengthField.setString("-1");
				startCharField.setLabel("Start Char (NA)");
				transmissionLengthField.setLabel("Length (Bytes) (NA)");

			} else if (delimitationStyle == ConnectionSettings.DELIMITATION_TRASMISSION_LENGTH) {
				// endCharField.setString("-1");
				// startCharField.setString("-1");
				startCharField.setLabel("Start Char (NA)");
				endCharField.setLabel("End Char (NA)");
			} else if (delimitationStyle == ConnectionSettings.DELIMITATION_TRASMISSION_LENGTH_AND_START_CHAR) {
				// endCharField.setString("-1");
				endCharField.setLabel("End Char (NA)");

			} else {
				startCharField.setLabel("Start Char (NA)");
				endCharField.setLabel("End Char (NA)");
				transmissionLengthField.setLabel("Length (Bytes) (NA)");
			}
			endChar = Integer.parseInt(endCharField.getString());
			startChar = Integer.parseInt(startCharField.getString());
			bytesInTransmission = Integer.parseInt(transmissionLengthField.getString());
			requestChar = Integer.parseInt(requestCharField.getString());
		
		}
		}
	}


}
